<template>
  <div class="company-info-page">
    <!-- 顶部导航 -->
    <div class="top-nav">
      <el-button text @click="goBack" class="back-btn">
        <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M19 12H5M5 12L12 19M5 12L12 5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
        </svg>
        <span>返回</span>
      </el-button>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-container">
      <!-- 企业头部信息 -->
      <div class="company-header">
        <div class="header-content">
          <div class="logo-wrapper">
            <el-avatar :size="100" :src="company.logo || defaultLogo" class="company-logo">
              <img v-if="!company.logo" src="/upload/img.png" alt="Logo" />
            </el-avatar>
            <div v-if="company.is_verified" class="verified-badge">
              <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M20 6L9 17L4 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
              </svg>
            </div>
          </div>
          <div class="company-intro">
            <h1 class="company-name">{{ company.name || '未设置企业名称' }}</h1>
            <p class="company-short" v-if="company.short_name">{{ company.short_name }}</p>
            <div class="company-meta">
              <span v-if="getIndustryText(company.industry)" class="meta-item">
                {{ getIndustryText(company.industry) }}
              </span>
              <span v-if="getScaleText(company.scale)" class="meta-item">
                {{ getScaleText(company.scale) }}
              </span>
              <span v-if="company.is_verified" class="meta-item verified">
                已认证
              </span>
            </div>
          </div>
        </div>
      </div>

      <!-- 数据统计 -->
      <div class="stats-section">
        <div class="stat-card">
          <div class="stat-number">{{ fixedData.totalJobs }}</div>
          <div class="stat-text">在招职位</div>
        </div>
        <div class="stat-card">
          <div class="stat-number">{{ fixedData.totalEmployees }}</div>
          <div class="stat-text">员工总数</div>
        </div>
        <div class="stat-card">
          <div class="stat-number">{{ fixedData.activeRecruiters }}</div>
          <div class="stat-text">活跃招聘者</div>
        </div>
        <div class="stat-card">
          <div class="stat-number">{{ fixedData.responseRate }}%</div>
          <div class="stat-text">回复率</div>
        </div>
      </div>

      <!-- 详细信息区域 -->
      <div class="info-section">
        <div class="info-left">
          <!-- 基本信息 -->
          <div class="info-block">
            <h2 class="block-title">基本信息</h2>
            <div class="info-list">
              <div class="info-row">
                <span class="info-label">企业全称</span>
                <span class="info-value">{{ company.name || '—' }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">企业简称</span>
                <span class="info-value">{{ company.short_name || '—' }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">公司规模</span>
                <span class="info-value">{{ getScaleText(company.scale) || '—' }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">所属行业</span>
                <span class="info-value">{{ getIndustryText(company.industry) || '—' }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">公司地址</span>
                <span class="info-value">{{ company.address || '—' }}</span>
              </div>
              <div class="info-row">
                <span class="info-label">工商注册号</span>
                <span class="info-value">{{ company.business_license || '—' }}</span>
              </div>
            </div>
          </div>

          <!-- 企业简介 -->
          <div class="info-block">
            <h2 class="block-title">企业简介</h2>
            <div class="description-text">
              <p v-if="company.description">{{ company.description }}</p>
              <p v-else class="empty-text">暂无企业简介</p>
            </div>
          </div>
        </div>

        <div class="info-right">
          <!-- 企业荣誉 -->
          <div class="info-block">
            <h2 class="block-title">企业荣誉</h2>
            <div class="honors-list">
              <div v-for="(honor, index) in fixedData.honors" :key="index" class="honor-item">
                <div class="honor-dot"></div>
                <span>{{ honor }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = useRouter()
const defaultLogo = '/upload/img.png'

// 企业信息
const company = reactive({
  id: null,
  name: '',
  short_name: '',
  scale: '',
  description: '',
  address: '',
  industry: '',
  logo: '',
  business_license: '',
  is_verified: false
})

// 固定数据（写死）
const fixedData = reactive({
  totalJobs: 156,
  totalEmployees: 1200,
  activeRecruiters: 8,
  responseRate: 95,
  honors: [
    '2023年度最佳雇主',
    '高新技术企业认证',
    'ISO 9001质量管理体系认证',
    'AAA级信用企业',
    '优秀互联网企业'
  ]
})

// 规模映射
const scaleMap = {
  '1-50': '1-50人',
  '50-100': '50-100人',
  '100-500': '100-500人',
  '500-1000': '500-1000人',
  '1000+': '1000人以上'
}

// 行业映射
const industryMap = {
  'internet': '互联网',
  'finance': '金融',
  'education': '教育',
  'healthcare': '医疗',
  'manufacturing': '制造业',
  'real_estate': '房地产',
  'other': '其他'
}

function getScaleText(scale) {
  return scaleMap[scale] || scale || '—'
}

function getIndustryText(industry) {
  return industryMap[industry] || industry || '—'
}

function goBack() {
  router.back()
}

onMounted(() => {
  // 从sessionStorage获取企业信息
  const companyInfoStr = sessionStorage.getItem('companyInfo')
  if (companyInfoStr) {
    try {
      const companyInfo = JSON.parse(companyInfoStr)
      Object.assign(company, companyInfo)
    } catch (e) {
      console.error('解析企业信息失败:', e)
      ElMessage.error('加载企业信息失败')
    }
  } else {
    ElMessage.warning('未找到企业信息')
  }
})
</script>

<style scoped>
.company-info-page {
  min-height: 100vh;
  background: #fafbfc;
}

/* 顶部导航 */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #f0f2f5;
  padding: 16px 0;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #666;
  font-size: 14px;
  padding: 8px 16px;
  margin-left: 24px;
  border-radius: 8px;
  transition: all 0.2s;
}

.back-btn:hover {
  color: #00c293;
  background: rgba(0, 194, 147, 0.08);
}

.back-btn svg {
  width: 18px;
  height: 18px;
}

/* 主容器 */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px;
}

/* 企业头部 */
.company-header {
  background: linear-gradient(135deg, #ffffff 0%, #f8fafb 100%);
  border-radius: 20px;
  padding: 48px;
  margin-bottom: 32px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.header-content {
  display: flex;
  align-items: flex-start;
  gap: 32px;
}

.logo-wrapper {
  position: relative;
  flex-shrink: 0;
}

.company-logo {
  border: 3px solid #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.verified-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 32px;
  height: 32px;
  background: #00c293;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 194, 147, 0.3);
}

.verified-badge svg {
  width: 18px;
  height: 18px;
}

.company-intro {
  flex: 1;
}

.company-name {
  font-size: 36px;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0 0 12px 0;
  letter-spacing: -0.5px;
}

.company-short {
  font-size: 18px;
  color: #666;
  margin: 0 0 20px 0;
  font-weight: 400;
}

.company-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.meta-item {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  background: #f0f2f5;
  border-radius: 20px;
  font-size: 14px;
  color: #666;
  font-weight: 500;
}

.meta-item.verified {
  background: #e6f7f0;
  color: #00c293;
}

/* 数据统计 */
.stats-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: #fff;
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  transition: all 0.3s;
  border: 1px solid #f0f2f5;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.stat-number {
  font-size: 40px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 8px;
  line-height: 1;
}

.stat-text {
  font-size: 14px;
  color: #999;
  font-weight: 500;
}

/* 详细信息区域 */
.info-section {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 32px;
}

.info-block {
  background: #fff;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  border: 1px solid #f0f2f5;
}

.block-title {
  font-size: 20px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0 0 24px 0;
  padding-bottom: 16px;
  border-bottom: 2px solid #f0f2f5;
}

.info-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.info-label {
  font-size: 14px;
  color: #999;
  font-weight: 500;
  min-width: 100px;
  flex-shrink: 0;
}

.info-value {
  font-size: 15px;
  color: #333;
  font-weight: 500;
  text-align: right;
  flex: 1;
}

.description-text {
  font-size: 15px;
  line-height: 1.8;
  color: #666;
  white-space: pre-wrap;
}

.description-text p {
  margin: 0;
}

.empty-text {
  color: #ccc;
  font-style: italic;
}

.honors-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.honor-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  color: #333;
  line-height: 1.6;
}

.honor-dot {
  width: 6px;
  height: 6px;
  background: #00c293;
  border-radius: 50%;
  flex-shrink: 0;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .info-section {
    grid-template-columns: 1fr;
  }
  
  .stats-section {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .main-container {
    padding: 24px 16px;
  }
  
  .company-header {
    padding: 32px 24px;
  }
  
  .header-content {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  
  .company-name {
    font-size: 28px;
  }
  
  .stats-section {
    grid-template-columns: 1fr;
  }
  
  .info-block {
    padding: 24px;
  }
  
  .info-row {
    flex-direction: column;
    gap: 8px;
  }
  
  .info-value {
    text-align: left;
  }
}
</style>
